package com.yunxitest.yunxitest.item.light

import com.yunxitest.yunxitest.Interface.IDetectItem
import java.util.*

class LightDetectManager : IDetectItem {
    private var timer :Timer? =null
    override fun startDetect() {
        timer=Timer()
        blink()
    }

    override fun finish() {
        timer?.cancel()
        timer=null
    }


    fun blink() {
        val task = object : TimerTask() {
            var count = 0
            override fun run() {
                if (count == 3) count = 0
                when (count) {
                    0 -> {
                        LedUtil.setledlightcolor(LedUtil.OFF)
                    }
                    1 -> {
                        LedUtil.setledlightcolor(LedUtil.GREEN)
                    }
                    2 -> {
                        LedUtil.setledlightcolor(LedUtil.RED)
                    }
                }
                count++
            }
        }
        timer?.schedule(task, 0, 200)
    }
}